/* =============================================================================
#     FileName: wl_ringbuff.h
#     Desc:
#     LastChange:
#     History:
============================================================================= */
#ifndef __WL_RINGBUFF_H
#define __WL_RINGBUFF_H

#include "stdint.h"

typedef enum 
{
    FALSE = 0,
    TRUE = 1
} bool_e;


enum {
    ERR_RINGBUF_INVALID_ID      = -1,
    ERR_RINGBUF_INVALID_PARAM   = -2,
    ERR_RINGBUF_WRITE_BUSY      = -3,
    ERR_RINGBUF_READ_BUSY       = -4,
    ERR_RINGBUF_BUF_FULL        = -5,
    ERR_RINGBUF_BUF_EMPTY       = -6,
};

#define  DMA_DATALEN_LEN   4
typedef struct
{
    uint8_t*      ps8Name;
    uint8_t*      ps8Buf;
    volatile uint16_t   u16RItemID;   // read buffer id
    volatile uint16_t   u16WItemID;   // write buffer id    
    uint16_t   u16Items;     // buffer items
    uint16_t   u16ItemSize;  // buffer item size
    volatile uint16_t   u16FullFlag;
    volatile uint8_t    u8ReadingFlag;
    volatile uint8_t    u8WritingFlag;

    uint16_t leftItem;
    uint16_t minLeftItem;
}Ringbuf_st;

int32_t wl_ringbuf_write(Ringbuf_st* ring, uint8_t* data, uint32_t size);
int32_t wl_ringbuf_writeOver(Ringbuf_st* ring, uint8_t* data, uint32_t size);
int32_t wl_ringbuf_read(Ringbuf_st* ring, uint8_t* data, uint32_t* size);
uint16_t wl_ringbuf_containSize(Ringbuf_st* ring);
uint16_t wl_ringbuf_freeSize(Ringbuf_st* ring);
int32_t wl_ringbuf_clear(Ringbuf_st* ring);

#endif /*__WL_RINGBUFF_H */

